unsigned int flags;
};
+/*****************************
+ * Private range functions hide the underlying linked-list implemnetation.
+ */
+
/* Find highest range lower than or containing s. NULL if no such range. */
static struct range *find_range(
struct rangeset *r, unsigned long s)
return list_entry(x->list.next, struct range, list);
}
+/* Insert range y after range x in r. Insert as first range if x is NULL. */
+static void insert_range(
+ struct rangeset *r, struct range *x, struct range *y)
+{
+ list_add(&y->list, (x != NULL) ? &x->list : &r->range_list);
+}
+
/* Remove a range from its list and free it. */
static void destroy_range(
struct range *x)
xfree(x);
}
+/*****************************
+ * Core public functions
+ */
+
int rangeset_add_range(
struct rangeset *r, unsigned long s, unsigned long e)
{
x->s = s;
x->e = e;
- list_add(&x->list, (y != NULL) ? &y->list : &r->range_list);
+ insert_range(r, y, x);
}
-
- if ( x->e < e )
+ else if ( x->e < e )
x->e = e;
}
else
rc = -ENOMEM;
goto out;
}
+
y->s = e + 1;
y->e = x->e;
x->e = s - 1;
- list_add(&y->list, &x->list);
+
+ insert_range(r, x, y);
}
else if ( (x->s == s) && (x->e <= e) )
destroy_range(x);
}
}
+/*****************************
+ * Pretty-printing functions
+ */
+
static void print_limit(struct rangeset *r, unsigned long s)
{
printk((r->flags & RANGESETF_prettyprint_hex) ? "%lx" : "%lu", s);
printk("%10s {", r->name);
- list_for_each_entry ( x, &r->range_list, list )
+ for ( x = first_range(r); x != NULL; x = next_range(r, x) )
{
if ( nr_printed++ )
printk(",");